/*
 * File      : led.c
 * This file is part of stm32 led driver
 *
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-06-25          
 */
 
#include "led.h"
#include "stm32f2xx_gpio.h"
#include "stm32f2xx_rcc.h"
 
#include <board.h>
#include <rtthread.h>
 
#define led1_rcc                    RCC_AHB1Periph_GPIOA
#define led1_gpio                   GPIOA
#define led1_pin                    (GPIO_Pin_15)

/*
 led gpio driver.
 */
 void led_gpio_init(void)
 {
	 GPIO_InitTypeDef GPIO_InitStruct;
	 RCC_AHB1PeriphClockCmd(led1_rcc, ENABLE);
	 
			 /*Configure GPIO pin : PA15 */
		GPIO_InitStruct.GPIO_Pin = led1_pin;
		GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
		GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
		GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_Init(led1_gpio, &GPIO_InitStruct);
 }
 
 /*
 led on.
 */
 void led_on(void)
 {
	 GPIO_SetBits(led1_gpio,led1_pin);
 }
 
  /*
 led off.
 */
 void led_off(void)
 {
	 GPIO_ResetBits(led1_gpio,led1_pin);
 }
 
 /*
 led task.
 */
 void led_thread_entry(void *parameter)
 {
	 led_gpio_init();
	 while(1)
	 {
		 led_on();
		 rt_thread_delay( RT_TICK_PER_SECOND/2 );
		 led_off();
		 rt_thread_delay( RT_TICK_PER_SECOND/2 );
	 }
 }
 
 